<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@include file="/common/definition.jsp"%>
<%@ page language="java" import="java.util.*"%>
<html:html>
<tiles:insert beanName="homepage-definition" flush="true">
	<tiles:put name="title"> Chi Tiết Sản Phẩm  </tiles:put>
	<tiles:put name="body" type="string">
<% int i = 0; %>
<s:iterator value="listAgentProduct">
<% i ++; %>
</s:iterator>
	<div class="col-md-12">
	<div class="mainHome" style="min-height : 1300px; padding: 20px">
			<div class="col-md-12">
				<br> <br>
			</div>
			<div class="row">
				<div class="col-md-12">
					<h2>
						<s:property value="productModel.productInfo.brandName" />
						<s:property value="productModel.productInfo.productName" />
					</h2>
				</div>
				<!-- TABLE PRODUCTS START -->
					
				<div class="col-md-3" >
				<table class="table">
				<tr>
					<td class="col-md-4 popup-gallery">
						<s:iterator value="productModel.productInfo.listLinkImg" status="status">
							<s:if test="#status.first == true">
								<div class="col-md-12 paddingImg">
									<!-- ảnh lớn ở trên -->
									<a href="<s:property/>" class="thumbnail"> <img src='<s:property/>'
										width="100%"> </a>
								</div>
							</s:if>
						</s:iterator>
						<div class=" col-md-12 row">
							<s:iterator value="productModel.productInfo.listLinkImg"
								status="status">
								<s:if test="#status.first == true">
								</s:if>
								<s:else>
									<!-- ảnh bé ở dưới -->
									<div class="col-md-3 paddingImg">
										<a href="<s:property/>" class="thumbnail"> <img src='<s:property/>' width="100%"> </a>
									</div>
								</s:else>
							</s:iterator>
						</div>
					</td>
				</tr>
				</table>
				<table class="table">
				<tr>
				<td class="col-md-10">
					<div class="description">
						<h4>Thông tin sản phẩm</h4>
						<br> <span>Nhà sản xuất:</span>
						<s:property value="productModel.productInfo.brandName" />
						<br> <span>Gian hàng bán:</span> 
							<s:a action="viewShopByProduct">
								có <%= i %> gian hàng đang bán
								<s:param name="productID" value="%{productInfo.productID}" /> 
							</s:a> 
					</div><br>
					<div class=" col-md-12 row text-center">
						<s:if test="#session.role == 1 || #session.role == 2">
							<s:a action="detailProductLink" cssClass="btn btn-primary" role="button">Chỉnh sửa thông tin
							<s:param name="productID" value="%{productInfo.productID}" /> </s:a>
						</s:if>
						<s:elseif test="#session.role == 5">
						
						</s:elseif>
						<s:elseif test="#session.role != null">
							<s:if test="productInfo.favorite == 1 || productInfo.favorite == 3">
								<s:a action="addFavoriteProduct" cssClass="btn btn-default disabled" role="button">
									Yêu thích <s:param name="productID" value="%{productInfo.productID}" />
								</s:a>
							</s:if>
							<s:else>
								<s:a action="addFavoriteProduct" cssClass="btn btn-default"
									role="button">
									Yêu thích<s:param name="productID" value="%{productInfo.productID}" />
									<s:param name="type" value="1" />
								</s:a>
							</s:else>
						</s:elseif>

						<s:if test="#session.role == 1 || #session.role == 2">
							<s:a action="imageManage-page" cssClass="btn btn-success" role="button">Chỉnh sửa hình ảnh
							<s:param name="productID" value="%{productInfo.productID}" /> </s:a>
						</s:if>
						<s:if test="#session.role == 5">
							<s:if test="productInfo.favorite == 4">
								<s:a cssClass="btn btn-danger disabled" action="saleLink">Sản phẩm đang được bán tại cửa hàng
								<s:param name="productID" value="%{productInfo.productID}" /> </s:a>
							</s:if>
							<s:else>
								<s:a cssClass="btn btn-primary" action="saleLink">Đăng bán sản phẩm
								<s:param name="productID" value="%{productInfo.productID}" /> </s:a>
							</s:else>
						</s:if>
						<s:elseif test="#session.role == 4">
							<s:if test="productInfo.favorite == 2 || productInfo.favorite == 3">
								<s:a action="addFavoriteProduct" cssClass="btn btn-default disabled" role="button">
									Sản phẩm đang theo dõi<s:param name="productID" value="%{productInfo.productID}" />
								</s:a>
							</s:if>
							<s:else>
								<s:a action="addFavoriteProduct" cssClass="btn btn-default" role="button">
									Theo dõi sản phẩm <s:param name="productID" value="%{productInfo.productID}" />
									<s:param name="type" value="2" />
								</s:a>
							</s:else>
						</s:elseif>
					</div></td>
					</tr>
				</table>
				</div>
				<script type="text/javascript">
			    $(document).ready(function() {
			      $('.popup-gallery').magnificPopup({
			        delegate: 'a',
			        type: 'image',
			        tLoading: 'Loading image #%curr%...',
			        mainClass: 'mfp-img-mobile',
			        gallery: {
			          enabled: true,
			          navigateByImgClick: true,
			          preload: [0,1] // Will preload 0 - before current, and 1 after the current image
			        },
			        image: {
			          tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
			          titleSrc: function(item) {
			            return item.el.attr('title') + '<small>by Marsel Van Oosten</small>';
			          }
			        }
			      });
			    });
			  </script>	
				
				<!-- TABLE PRODUCTS END -->
				<div class="col-md-9">
					<s:if test="listAgentProduct == null">
						<h4>Hiện không có của hàng bán sản phẩm này</h4>
					</s:if>
					<h4>Các cửa hàng bán sản phẩm có giá thấp nhất</h4>
					<table class="table borderAll" >
						<tr>
							<td class="col-md-1"></td>
							<th class="col-md-2	"><p>Cửa hàng</p> </th>
							<th class="col-md-2 text-center"><p>Giá niêm yết</p> </th>
							<th class="col-md-2 text-center"><p>Giá khuyến mãi</p> </th>
							<th class="col-md-2 text-center"><p>Tình trạng</p> </th>
							<th class="col-md-2"><p>Bảo hành</p> </th>
						</tr>
						<s:if test="listAgentProduct.isEmpty()">
							<td colspan="5">hiện chưa có cửa hàng bán sản phẩm này</td>
						</s:if>
						<s:iterator value="listAgentProduct">
							<tr>
								<td><p>
										<s:a action="shopHome"><img src='<s:property value="logo"/>' width="100%" />
										<s:param name="agentID"><s:property value="agentID"/></s:param></s:a>
									</p>
								</td>
								<td><p>
									<s:a action="shopHome"><s:property value="agentName" />
									<s:param name="agentID"><s:property value="agentID"/></s:param></s:a>
									</p>
								</td>
								<td>
									<p class="text-success text-right"><s:property value="sellingPrice" />000 vnd</p>
								</td>
								<td>
									<s:if test="discount == null">
										<p class="text-success text-right">Không có giảm giá</p>
									</s:if><s:else>
										<p class="text-danger text-right"><s:property value="discount" />000 vnd 
										<br><strong>Sale off <s:property value="discountPercent"/> %</strong></p>
									</s:else>
								</td>
								<s:if test="condition == 'BrandNew'">
									<td class="text-center"><p>Mới</p>
									</td>
								</s:if>
								<s:elseif test="condition == 'SecondHand'">
									<td><p>Đã Qua Sử Dụng</p>
									</td>
								</s:elseif>
								<td><p>
										<s:property value="warranty"/>&nbsp;Tháng<br>
										<s:a action="detailShopProduct"> xem tại cửa hàng
										<s:param name="listID"><s:property value="listID"/></s:param></s:a>
									</p>
								</td>
							</tr>
						</s:iterator>
					</table>
				</div>
			</div>
			<div class="col-md-12" style="padding-left: 0px; padding-top: 50px;">
				<h3 class="text-left borderBot">Thông số chi tiết của sản phẩm</h3><br><br><br>
				<div class="mainHome" style="padding-bottom: 150px; padding-top: 15px; padding-left: 20px;">
					<s:property value="productModel.productInfo.contentOfWeb" escape="false" />
				</div>
			</div>
	</div>
	</div>
	</tiles:put>
</tiles:insert>
</html:html>
